import cv2
import os
import numpy as np
from matplotlib import pyplot as plt

txt_path = "img/imgXY.txt"
xy_dict = {}

with open(txt_path) as f:
    for line in f:
        args = line.split()
        X2 = int(args[1]) + int(args[3])
        Y2 = int(args[2]) + int(args[4]) - 21
        xy_dict[args[0]] = [(int(args[1]), int(args[2])), (X2, Y2)]

plt.figure(figsize=(17, 7))
for index, (name, xy) in enumerate(xy_dict.items()):
    image = cv2.imread(os.path.join("img", name))
    cv2.rectangle(image, xy[0], xy[1], (0, 255, 0), 2)
    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    plt.subplot(2, 5, index + 1)
    plt.imshow(image)
    plt.axis('off')
    plt.title(name)
plt.show()
